export function drawGrid(
  canvas, // 画布
  context, // 上下文
  gridSpace, // 每个格子宽度
  gridLineColor, // 网格线颜色
  LineDashStyle // 虚线参数(可为数组)
) {
  // 纵轴, 横轴网格线数量
  let xLines = Math.floor(canvas.width / gridSpace);
  let yLines = Math.floor(canvas.height / gridSpace);
  // 画横线
  for (let i = 0; i <= yLines; i++) {
    context.beginPath();
    context.moveTo(0, 0 + i * gridSpace);
    context.lineTo(canvas.width, 0 + i * gridSpace);
    context.lineWidth = 1;
    context.setLineDash([`${LineDashStyle}`]);
    context.strokeStyle = gridLineColor;
    context.stroke();
  }
  // 画竖线
  for (let i = 0; i <= xLines; i++) {
    context.beginPath();
    context.moveTo(0 + i * gridSpace, 0);
    context.lineTo(0 + i * gridSpace, canvas.height);
    context.lineWidth = 1;
    context.setLineDash([`${LineDashStyle}`]);
    context.strokeStyle = gridLineColor;
    context.stroke();
  }
}

export function autoCanvasSize(canvas) {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
}

export function setBackground(canvas, context, backgroundColor) {
  context.fillStyle = backgroundColor;
  context.fillRect(0, 0, canvas.width, canvas.height);
}